package com.getbyte.homework;

import java.io.*;
import java.util.Scanner;

/**
 * @author げっしょく
 * @date 2021/8/4
 */
public class Test2 {
    public static void main(String[] args) throws IOException {
        /*
         键盘录入数据源路径和目的地路径，分别使用【普通字符流】和【字符缓冲流的特殊功能】完成对指定文件的复制
    例如：
        数据源： d:\a.txt
        目的地： d:\b.txt

        就将a.txt文件的数据复制到b.txt中
         */
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要拷贝的源头：");
        BufferedReader br = new BufferedReader(new FileReader(sc.nextLine()));
        System.out.println("请输入你要拷贝在什么地方：");
        BufferedWriter bw = new BufferedWriter(new FileWriter(sc.nextLine()));
        String a ;
        while ((a = br.readLine()) != null){
            bw.write(a);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        br.close();
        //moth1使用的是普通字符流
        //moth1();
    }

    private static void moth1() throws IOException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要拷贝的源头：");
        FileReader fr = new FileReader(sc.nextLine());
        //String source = sc.nextLine();
        // FileReader fr = new FileReader(source);
        System.out.println("请输入你要拷贝在什么地方：");
        FileWriter fw = new FileWriter(sc.nextLine());
        //String destination = sc.nextLine();
        //FileWriter fw = new FileWriter(destination);
        int len = 0;
        char[] chars = new char[5];
        while ((len = fr.read(chars)) != -1){
            fw.write(chars , 0 , len);
        }
        fw.flush();
        fw.close();
        fr.close();
    }
}
